//- Copyright (c) 2016 Lucky Byte, Inc.
extends ../layout

append scripts
  script(src="/js/users/body.js")

block content
  form.ui.form.attached.segment.main(method="post" action="/users/edit"
    data-disabled="#{record.disabled}")
    - var in_edit = true
    include body

    .ui.buttons(style="margin-top:40px;")
      if page_perms.delete
        button.ui.red.button#delete(type="button"
          data-action='/users/delete') 删 除
      else
        button.ui.red.button.disabled#delete(type="button")
          i.icon.ban(style="margin-top:1px; margin-right:2px;")
          | 删 除

      if record.disabled
        if page_perms.disable
          button.ui.orange.button#disable(type="button"
            data-disabled="true" data-action="/users/disable") 启 用
        else
          button.ui.orange.button.disabled#disable(type="button"
            data-disabled="true")
            i.icon.ban(style="margin-top:1px; margin-right:2px;")
            | 启 用
      else
        if page_perms.disable
          button.ui.orange.button#disable(type="button"
            data-disabled="false" data-action="/users/disable") 禁 用
        else
          button.ui.orange.button.disabled#disable(type="button"
            data-disabled="false")
            i.icon.ban(style="margin-top:1px; margin-right:2px;")
            | 禁 用
  
      button.ui.yellow.button#cancel(type="button"
        onclick="window.location = '/users'") 取 消

      if page_perms.edit
        button.ui.green.button#ok(type="submit") 确 定
      else
        button.ui.green.button.disabled#ok(type="submit")
          i.icon.ban(style="margin-top:1px; margin-right:2px;")
          | 确 定

append code
  script.
    $(function() {
      $('form#users').form('set value', 'dept', '#{record.dept}');
    })
  script
    :coffee-script
      $ ->
          # 如果不修改用户密码，则使用一个特殊的密码值
          $('input[type="password"]').val("it's not a password")
          $('a#old_password').click (evt) ->
              $('input[type="password"]').val("it's not a password")
              evt.preventDefault()
